package cn.dgut.jy.soro.controller;

import cn.dgut.jy.soro.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class ProductController {
    private ProductService productService;

    @Autowired
    public ProductController(ProductService productService) {
        this.productService = productService;
    }

    @RequestMapping("/addProduct")
    String addProduct() {
        return "addProduct";
    }

    @RequestMapping("/add_product")
    String adding(Model model, @RequestParam String name, @RequestParam Float price, @RequestParam String details) {
        if(!productService.add(name, price, details)) {
            model.addAttribute("message", "名称重复");
        }

        return "addProduct";
    }

    @RequestMapping("/shop")
    String shop(Model model) {

        return "shop";
    }
}
